package com.bootdo.crm.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.crm.domain.BusinessChangeDO;
import com.bootdo.crm.service.BusinessChangeService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 商机阶段变化表
 * 
 * @author cui
 * @email 1992lcg@163.com
 * @date 2020-02-20 13:14:27
 */
 
@Controller
@RequestMapping("/crm/businessChange")
public class BusinessChangeController {
	@Autowired
	private BusinessChangeService businessChangeService;
	
	@GetMapping()
	@RequiresPermissions("crm:businessChange:businessChange")
	String BusinessChange(){
	    return "crm/businessChange/businessChange";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("crm:businessChange:businessChange")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<BusinessChangeDO> businessChangeList = businessChangeService.list(query);
		int total = businessChangeService.count(query);
		PageUtils pageUtils = new PageUtils(businessChangeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("crm:businessChange:add")
	String add(){
	    return "crm/businessChange/add";
	}

	@GetMapping("/edit/{changeId}")
	@RequiresPermissions("crm:businessChange:edit")
	String edit(@PathVariable("changeId") Integer changeId,Model model){
		BusinessChangeDO businessChange = businessChangeService.get(changeId);
		model.addAttribute("businessChange", businessChange);
	    return "crm/businessChange/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("crm:businessChange:add")
	public R save( BusinessChangeDO businessChange){
		if(businessChangeService.save(businessChange)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("crm:businessChange:edit")
	public R update( BusinessChangeDO businessChange){
		businessChangeService.update(businessChange);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("crm:businessChange:remove")
	public R remove( Integer changeId){
		if(businessChangeService.remove(changeId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("crm:businessChange:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] changeIds){
		businessChangeService.batchRemove(changeIds);
		return R.ok();
	}
	
}
